package com.mmall.concurrency.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @author shaozhiyong@huice.com
 * @description: TODO
 * @date 2022/2/7 17:03
 */
@RestController
@Slf4j
public class TestListener {
    @Autowired
    ApplicationContext context;

    @RequestMapping("/detail")
    public String test(){
        LazadaTransactionEvent.LazadaTransactionData lazadaTransactionData = new LazadaTransactionEvent.LazadaTransactionData();
        lazadaTransactionData.setSid("1");
        lazadaTransactionData.setShopId("2");
        lazadaTransactionData.setStartDate("3");
        lazadaTransactionData.setEndDate("4");
        context.publishEvent(new LazadaTransactionEvent(lazadaTransactionData));
        return "success";
    }

    @EventListener
    public void transactionListen(LazadaTransactionEvent lazadaTransactionEvent){
        LazadaTransactionEvent.LazadaTransactionData lazadaTransactionData
                = (LazadaTransactionEvent.LazadaTransactionData) lazadaTransactionEvent.getSource();
        System.out.println("lazadaTransactionData:{}"+lazadaTransactionData);
    }
}
